import React, { useEffect, useState } from 'react'
import { Layout, Table, message } from 'antd'
import axios from 'axios'
const { Content } = Layout



export default function RightList () {

  const [rightList, setRightList] = useState([])

  //获取权限列表
  useEffect(() => {
    axios.get("http://localhost:8081/permission/getRightList",
      {
        headers: {
          satoken: localStorage.getItem("satoken")
        }
      }
    ).then(r => {
      console.log(r.data)
      if (r.data.code !== 200) {
        return message.error(r.data.msg)
      } else {
        //console.log(r.data.data)
        r.data.data.map((item) => {
          item.key = item.id
          return item
        })
        setRightList(r.data.data)
        return message.success(r.data.msg)
      }
    })
  }, [])

  //表格头，字段
  const columns = [
    {
      title: '序号',
      dataIndex: 'id',
      key: 'id',
      align: 'center',
      width: '20%',
    },
    {
      title: '权限名',
      dataIndex: 'name',
      key: 'name',
      align: 'center',
      width: '30%',
      //render: (data, record) => renderMenus(data, record)
    }

  ]


  return (
    <Content className='rolelistContent'>
      {/* 表格 */}
      <Table
        bordered
        columns={columns}
        dataSource={rightList}
        defaultExpandAllRows={false}
        pagination={{ pageSize: 7 }}//自定义每页显示的数据条数
      ></Table>
    </Content>
  )
}
